home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / iterator.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  5.3 KB  |  157 lines

  1. #ifndef __ITERATOR_CC
  2. #define __ITERATOR_CC
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * iterator.cc - Non-inline definitions for the Standard Library iterators
  8.  *
  9.  * $Id: iterator.cc,v 1.3 1996/08/28 18:42:00 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * Copyright (c) 1994
  14.  * Hewlett-Packard Company
  15.  *
  16.  * Permission to use, copy, modify, distribute and sell this software
  17.  * and its documentation for any purpose is hereby granted without fee,
  18.  * provided that the above copyright notice appear in all copies and
  19.  * that both that copyright notice and this permission notice appear
  20.  * in supporting documentation.  Hewlett-Packard Company makes no
  21.  * representations about the suitability of this software for any
  22.  * purpose.  It is provided "as is" without express or implied warranty.
  23.  *
  24.  *
  25.  ***************************************************************************
  26.  *
  27.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  28.  * ALL RIGHTS RESERVED *
  29.  * The software and information contained herein are proprietary to, and
  30.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  31.  * intends to preserve as trade secrets such software and information.
  32.  * This software is furnished pursuant to a written license agreement and
  33.  * may be used, copied, transmitted, and stored only in accordance with
  34.  * the terms of such license and with the inclusion of the above copyright
  35.  * notice.  This software and information or any other copies thereof may
  36.  * not be provided or otherwise made available to any other person.
  37.  *
  38.  * Notwithstanding any other lease or license that may pertain to, or
  39.  * accompany the delivery of, this computer software and information, the
  40.  * rights of the Government regarding its use, reproduction and disclosure
  41.  * are as set forth in Section 52.227-19 of the FARS Computer
  42.  * Software-Restricted Rights clause.
  43.  * 
  44.  * Use, duplication, or disclosure by the Government is subject to
  45.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  46.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  47.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  48.  * P.O. Box 2328, Corvallis, Oregon 97339.
  49.  *
  50.  * This computer software and information is distributed with "restricted
  51.  * rights."  Use, duplication or disclosure is subject to restrictions as
  52.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  53.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  54.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  55.  * then the "Alternate III" clause applies.
  56.  *
  57.  **************************************************************************/
  58. #include <stdcomp.h>
  59.  
  60. #ifndef _RWSTD_NO_NAMESPACE
  61. namespace std {
  62. #endif
  63.  
  64. template <class InputIterator, class Distance>
  65. void __distance (InputIterator first, InputIterator last, Distance& n, 
  66.                  input_iterator_tag)
  67. {
  68.     while (first != last) { ++first; ++n; }
  69. }
  70.  
  71. template <class ForwardIterator, class Distance>
  72. void __distance (ForwardIterator first, ForwardIterator last, Distance& n, 
  73.                  forward_iterator_tag)
  74. {
  75.     while (first != last) { ++first; ++n; }
  76. }
  77.  
  78. template <class BidirectionalIterator, class Distance>
  79. void __distance (BidirectionalIterator first, BidirectionalIterator last, 
  80.                  Distance& n, bidirectional_iterator_tag)
  81. {
  82.     while (first != last) { ++first; ++n; }
  83. }
  84.  
  85.  
  86. #ifdef _RWSTD_NO_BASE_CLASS_MATCH
  87. //
  88. // We include assert() to test for possible problem in advance().
  89. // Furthermore, we FORCE assert() to always expand.
  90. //
  91. #ifdef  NDEBUG
  92. #define __RW_NDEBUG
  93. #undef  NDEBUG
  94. #endif
  95. #ifndef _RWSTD_NO_NEW_HEADER
  96. #include <cassert>
  97. #else
  98. #include <assert.h>
  99. #endif
  100.  
  101. #endif /*_RWSTD_NO_BASE_CLASS_MATCH*/
  102.  
  103.  
  104. template <class InputIterator, class Distance>
  105. void __advance (InputIterator& i, Distance n, input_iterator_tag)
  106. {
  107. #ifdef _RWSTD_NO_BASE_CLASS_MATCH
  108.     //
  109.     // All uses of advance() end up calling this template, even
  110.     // when advance() is being invoked on a bidirectional or random
  111.     // iterator.  We need to check that n is non-negative, or else
  112.     // this algorithm will fail horribly.  We MUST document the
  113.     // restriction that advance() only be called with non-negative
  114.     // Distance.  There don't appear to be any _EXPLICIT uses of advance()
  115.     // with a negative Distance argument in the STL library itself.
  116.     //
  117.     // This assert() is ALWAYS on -- see how it's included'd above.
  118.     //
  119.     assert(n >= 0);
  120. #endif /*_RWSTD_NO_BASE_CLASS_MATCH*/
  121.     while (n--) ++i;
  122. }
  123.  
  124. //
  125. // Don't forget to turn off expansion of assert() if that's what the
  126. // user expects.
  127. //
  128. #ifdef  __RW_NDEBUG
  129. #define NDEBUG
  130. #undef  __RW_NDEBUG
  131. #endif
  132.  
  133. template <class ForwardIterator, class Distance>
  134. void __advance (ForwardIterator& i, Distance n, forward_iterator_tag)
  135. {
  136.     while (n--) ++i;
  137. }
  138.  
  139. template <class BidirectionalIterator, class Distance>
  140. void __advance (BidirectionalIterator& i, Distance n, 
  141.                 bidirectional_iterator_tag)
  142. {
  143.     if (n >= 1)
  144.         while (n--) ++i;
  145.     else
  146.         while (n++) --i;
  147. }
  148.  
  149.  
  150.  
  151. #ifndef _RWSTD_NO_NAMESPACE
  152. }
  153. #endif
  154.  
  155. #pragma option pop
  156. #endif /* __ITERATOR_CC */
  157.